package cn.xshi.bpm.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.hutool.core.collection.CollectionUtil;
import cn.xshi.bpm.dao.*;
import cn.xshi.bpm.model.*;
import cn.xshi.bpm.param.NodeAttributeParam;
import cn.xshi.bpm.service.LcNodeAttributeService;
import cn.xshi.common.base.BaseService;
import cn.xshi.common.util.ExceptionUtil;
import cn.xshi.common.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
/**
 * @Desc 节点属性
 * @Author 邓纯杰
 * @CreateTime 2022-03-27 22:05:30
 */
@Service
@Slf4j
public class LcNodeAttributeServiceImpl extends BaseService implements LcNodeAttributeService {

	@Resource
	private LcNodeAttributeDao lcNodeAttributeDao;

	@Resource
	private LcJumpRulesDao lcJumpRulesDao;

	@Resource
	private LcNodeBtnDao lcNodeBtnDao;

	@Resource
	private LcNodeCandidateDao lcNodeCandidateDao;

	@Resource
	private LcNodeFormFieldDao lcNodeFormFieldDao;

	@Resource
	private LcBtnDao lcBtnDao;

	@Resource
	private LcProcessDao lcProcessDao;

	@Resource
	private LcDeploymentHisDao lcDeploymentHisDao;

	@Resource
	private LcNotifyTemplateDao lcNotifyTemplateDao;

	/**
	 * 分页
	 * @param condition
	 * @return
	 */
	public List<LcNodeAttribute> getLcNodeAttributeListByCondition(Map<String,Object> condition){
		try{
			return lcNodeAttributeDao.getLcNodeAttributeListByCondition(condition);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}

	/**
	 * 查询对象
	 * @param id
	 * @return
	 */
	public LcNodeAttribute getLcNodeAttributeById(String id){
		try{
			LcNodeAttribute lcNodeAttribute = lcNodeAttributeDao.getLcNodeAttributeById(id);
			if(null != lcNodeAttribute){
				if(!StringUtil.isEmpty(lcNodeAttribute.getMountsId())){//查询bpm文件
					LcProcess lcProcess = lcProcessDao.getLcProcessById(lcNodeAttribute.getMountsId());
					if(null != lcProcess){
						lcNodeAttribute.setBpm(lcProcess.getBpmn());
					}
				}
				if(!StringUtil.isEmpty(lcNodeAttribute.getHid_())){//查询bpm文件
					LcDeploymentHis lcDeploymentHis = lcDeploymentHisDao.getLcDeploymentHisById(lcNodeAttribute.getHid_());
					if(null != lcDeploymentHis){
						lcNodeAttribute.setBpm(lcDeploymentHis.getBpmn());
					}
				}
				Map<String,Object> condition = new HashMap<>();
				condition.put("lcNodeAttributeId",id);
				List<LcJumpRules> lcJumpRules = lcJumpRulesDao.getLcJumpRulesListByCondition(condition);
				List<LcJumpRules> btnRules = new ArrayList<>();
				if(!CollectionUtil.isEmpty(lcJumpRules)){
					List<LcJumpRules> jumpRulesList = new ArrayList<>();
					//过滤掉按钮下的自由规则
					for(LcJumpRules rules : lcJumpRules){
						if(StringUtil.isEmpty(rules.getNodeBtnId())){
							jumpRulesList.add(rules);
						}else{
							btnRules.add(rules);
						}
					}
					if(!CollectionUtil.isEmpty(jumpRulesList)){
						lcNodeAttribute.setLcJumpRules(jumpRulesList);
					}
				}
				List<LcNodeBtn> lcNodeBtns = lcNodeBtnDao.getLcNodeBtnListByCondition(condition);
				if(!CollectionUtil.isEmpty(lcNodeBtns)){
					for(LcNodeBtn lcNodeBtn : lcNodeBtns){
						if(StringUtil.isEmpty(lcNodeBtn.getBtnLabel())){
							lcNodeBtn.setBtnLabel(lcNodeBtn.getLabel_());//如果自定义按钮扩展label不存在则调用按钮中label
						}
						if(StringUtil.isEmpty(lcNodeBtn.getBtnAction())){
							lcNodeBtn.setBtnAction(lcNodeBtn.getBtnAction());//如果自定义扩展action为空 则调用按钮中action
						}

						if(!StringUtil.isEmpty(lcNodeBtn.getId())){
							List<LcJumpRules> lcBtnRules = new ArrayList<>();
							if(!CollectionUtil.isEmpty(btnRules)){
								for(LcJumpRules rules: btnRules){
									if(rules.getNodeBtnId().equals(lcNodeBtn.getId())){
										lcBtnRules.add(rules);
									}
								}
							}
							if(!CollectionUtil.isEmpty(lcBtnRules)){
								lcNodeBtn.setLcJumpRules(lcBtnRules);//设置按钮对应的节点跳转规则
							}
							lcNodeBtn.setLcBtn(lcBtnDao.getLcBtnById(lcNodeBtn.getBtnId()));
						}
					}
					lcNodeAttribute.setLcNodeBtns(lcNodeBtns);
				}
				List<LcNodeCandidate> lcNodeCandidates = lcNodeCandidateDao.getLcNodeCandidateListByCondition(condition);
				if(!CollectionUtil.isEmpty(lcNodeCandidates)){
					if(lcNodeCandidates.size() > 1){
						throw new ExceptionUtil("查出多个审批记录，错误！");
					}
					lcNodeAttribute.setLcNodeCandidate(lcNodeCandidates);
				}

				List<LcNodeFormField> lcNodeFormFields = lcNodeFormFieldDao.getLcNodeFormFieldListByCondition(condition);
				if(!CollectionUtil.isEmpty(lcNodeFormFields)){
					lcNodeAttribute.setNodeFormField(lcNodeFormFields);
				}

				//处理通知模板
				if(!StringUtil.isEmpty(lcNodeAttribute.getNotifyTemplateIds())){
					condition = new HashMap<>();
					condition.put("notifyTemplateIds",lcNodeAttribute.getNotifyTemplateIds().split(","));
				}
				List<LcNotifyTemplate> lcNotifyTemplates =  lcNotifyTemplateDao.getLcNotifyTemplateListByCondition(condition);
				if(!CollectionUtil.isEmpty(lcNotifyTemplates)){
					lcNodeAttribute.setLcNotifyTemplates(lcNotifyTemplates);
				}
			}
			return lcNodeAttribute;
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}

	/**
	 * 添加
	 * @param lcNodeAttribute
	 * @return
	 */
	public int addLcNodeAttribute(LcNodeAttribute lcNodeAttribute){
		int i = 0;
		try {
			i = lcNodeAttributeDao.addLcNodeAttribute(lcNodeAttribute);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 修改
	 * @param lcNodeAttribute
	 * @return
	 */
	public int updateLcNodeAttribute(LcNodeAttribute lcNodeAttribute){
		int i = 0;
		try {
			i = lcNodeAttributeDao.updateLcNodeAttribute(lcNodeAttribute);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 修改（根据动态条件）
	 * @param lcNodeAttribute
	 * @return
	 */
	public int updateLcNodeAttributeBySelective(LcNodeAttribute lcNodeAttribute){
		int i = 0;
		try {
			i = lcNodeAttributeDao.updateLcNodeAttributeBySelective(lcNodeAttribute);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 删除
	 * @param condition
	 * @return
	 */
	public int delLcNodeAttribute(Map<String,Object> condition){
		int i = 0;
		try {
			i = lcNodeAttributeDao.delLcNodeAttribute(condition);
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 保存
	 * @param lcNodeAttribute
	 * @return
	 */
	public int saveLcNodeAttribute(LcNodeAttribute lcNodeAttribute){
		int i = 0;
		try {
			if(StringUtil.isEmpty(lcNodeAttribute.getHid_()) && StringUtil.isEmpty(lcNodeAttribute.getMountsId())){
				throw new ExceptionUtil("挂载编号和历史版本号为空");
			}
			if(StringUtil.isEmpty(lcNodeAttribute.getLcProcessId())){
				throw new ExceptionUtil("流程id为空！");
			}
			if(StringUtil.isEmpty(lcNodeAttribute.getNodeId())){
				throw new ExceptionUtil("节点编号为空！");
			}
			//1.处理主信息
			if(StringUtil.isEmpty(lcNodeAttribute.getId())){

				//验证是否存在重复数据
				NodeAttributeParam nodeAttributeParam = new NodeAttributeParam();
				nodeAttributeParam.setNodeId(lcNodeAttribute.getNodeId());
				nodeAttributeParam.setMountsId(lcNodeAttribute.getMountsId());
				if(!StringUtil.isEmpty(lcNodeAttribute.getMountsId())){
					LcNodeAttribute attribute = getLcNodeAttribute(nodeAttributeParam);
					if(null != attribute){
						log.info("配置节点属性出现重复数据，挂载编号，节点！",lcNodeAttribute);
						throw new ExceptionUtil("配置节点属性出现重复数据，挂载编号，节点！");
					}
				}

				lcNodeAttribute.setId(toUUID());
				lcNodeAttribute.setCreateId(getCurrentAccountId());
				lcNodeAttribute.setCreateTime(getDate());
				i = lcNodeAttributeDao.addLcNodeAttribute(lcNodeAttribute);
			}else{
				i = lcNodeAttributeDao.updateLcNodeAttributeBySelective(lcNodeAttribute);
			}

			//2.处理按钮
			if(!CollectionUtil.isEmpty(lcNodeAttribute.getLcNodeBtns())){
				lcNodeBtnDao.delLcNodeBtnByAttributeId(lcNodeAttribute.getId());
				List<LcNodeBtn> lcNodeBtns = lcNodeAttribute.getLcNodeBtns();
				Map<String,Object> condition = new HashMap<>();
				condition.put("unNeedDelBtn",true);
				condition.put("lcNodeAttributeId",lcNodeAttribute.getId());
				lcJumpRulesDao.delLcJumpRulesByAttributeId(condition);//只删除包括按钮关联的节点
				for(LcNodeBtn lcNodeBtn : lcNodeBtns){
					lcNodeBtn.setCreateId(getCurrentAccountId());
					lcNodeBtn.setCreateTime(getDate());
					lcNodeBtn.setLcDeploymentId(lcNodeAttribute.getHid_());
					lcNodeBtn.setLcNodeAttributeId(lcNodeAttribute.getId());
					lcNodeBtn.setId(toUUID());
					lcNodeBtnDao.addLcNodeBtn(lcNodeBtn);
					List<LcJumpRules> lcJumpRules = lcNodeBtn.getLcJumpRules();
					if(!CollectionUtil.isEmpty(lcJumpRules)){
						for(LcJumpRules lcJumpRule : lcJumpRules){
							lcJumpRule.setCreateId(getCurrentAccountId());
							lcJumpRule.setCreateTime(getDate());
							lcJumpRule.setId(toUUID());
							lcJumpRule.setNodeBtnId(lcNodeBtn.getId());//设置按钮id
							lcJumpRule.setNodeId(lcNodeAttribute.getNodeId());
							lcJumpRule.setLcNodeAttributeId(lcNodeAttribute.getId());
							lcJumpRulesDao.addLcJumpRules(lcJumpRule);
						}
					}
				}
			}

			//3.处理跳转规则
			if(!CollectionUtil.isEmpty(lcNodeAttribute.getLcJumpRules())){
				Map<String,Object> condition = new HashMap<>();
				condition.put("lcNodeAttributeId",lcNodeAttribute.getId());
				condition.put("unNeedDelBtn",false);
				lcJumpRulesDao.delLcJumpRulesByAttributeId(condition);//只删除节点（不包括按钮关联的节点）
				List<LcJumpRules> lcJumpRules = lcNodeAttribute.getLcJumpRules();
				for(LcJumpRules lcJumpRule : lcJumpRules){
					lcJumpRule.setCreateId(getCurrentAccountId());
					lcJumpRule.setCreateTime(getDate());
					lcJumpRule.setId(toUUID());
					lcJumpRule.setNodeId(lcNodeAttribute.getNodeId());
					lcJumpRule.setLcNodeAttributeId(lcNodeAttribute.getId());
					lcJumpRulesDao.addLcJumpRules(lcJumpRule);
				}
			}

			//4.处理审批人
			if(!CollectionUtil.isEmpty(lcNodeAttribute.getLcNodeCandidate())){
				lcNodeCandidateDao.delLcNodeCandidateByAttributeId(lcNodeAttribute.getId());
				List<LcNodeCandidate> lcNodeCandidates = lcNodeAttribute.getLcNodeCandidate();
				for(LcNodeCandidate lcNodeCandidate : lcNodeCandidates){
					lcNodeCandidate.setLcDeploymentId(lcNodeAttribute.getHid_());
					lcNodeCandidate.setNodeId(lcNodeAttribute.getNodeId());
					lcNodeCandidate.setLcProcessId(lcNodeAttribute.getLcProcessId());
					lcNodeCandidate.setLcNodeAttributeId(lcNodeAttribute.getId());
					lcNodeCandidate.setCreateId(getCurrentAccountId());
					lcNodeCandidate.setCreateTime(getDate());
					lcNodeCandidate.setId(toUUID());
					lcNodeCandidateDao.addLcNodeCandidate(lcNodeCandidate);
				}
			}

			//5.字段权限
			if(!CollectionUtil.isEmpty(lcNodeAttribute.getNodeFormField())){
				lcNodeFormFieldDao.delLcNodeFormFieldAttributeId(lcNodeAttribute.getId());
				List<LcNodeFormField> lcNodeFormFields = lcNodeAttribute.getNodeFormField();
				for(LcNodeFormField lcNodeFormField : lcNodeFormFields){
					lcNodeFormField.setCreateId(getCurrentAccountId());
					lcNodeFormField.setCreateTime(getDate());
					lcNodeFormField.setId(toUUID());
					lcNodeFormField.setNodeId(lcNodeAttribute.getNodeId());
					lcNodeFormField.setLcNodeAttributeId(lcNodeAttribute.getId());
					lcNodeFormFieldDao.addLcNodeFormField(lcNodeFormField);
				}
			}

		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 强制同步
	 * @param lcNodeAttribute
	 * @return
	 */
	public int syncLcNodeAttribute(LcNodeAttribute lcNodeAttribute){
		int i = 0;
		try {
			if(StringUtil.isEmpty(lcNodeAttribute.getId())){
				throw new ExceptionUtil("节点属性id为空！");
			}
			if(StringUtil.isEmpty(lcNodeAttribute.getHid_()) && StringUtil.isEmpty(lcNodeAttribute.getMountsId())){
				throw new ExceptionUtil("挂载编号和历史版本号为空");
			}
			if(StringUtil.isEmpty(lcNodeAttribute.getLcProcessId())){
				throw new ExceptionUtil("流程id为空！");
			}
			if(StringUtil.isEmpty(lcNodeAttribute.getNodeId())){
				throw new ExceptionUtil("节点编号为空！");
			}

			//1.处理主信息
//			lcNodeAttributeDao.delLcNodeAttributeById(lcNodeAttribute.getId());//强删
			i = lcNodeAttributeDao.addLcNodeAttribute(lcNodeAttribute);//重新添加

			//2.处理按钮
			if(!CollectionUtil.isEmpty(lcNodeAttribute.getLcNodeBtns())){
//				lcNodeBtnDao.delLcNodeBtnByAttributeId(lcNodeAttribute.getId());
				List<LcNodeBtn> lcNodeBtns = lcNodeAttribute.getLcNodeBtns();
//				Map<String,Object> condition = new HashMap<>();
//				condition.put("unNeedDelBtn",true);
//				condition.put("lcNodeAttributeId",lcNodeAttribute.getId());
//				lcJumpRulesDao.delLcJumpRulesByAttributeId(condition);//只删除包括按钮关联的节点
				for(LcNodeBtn lcNodeBtn : lcNodeBtns){
					lcNodeBtn.setUpdateId(getCurrentAccountId());
					lcNodeBtn.setUpdateTime(getDate());
					lcNodeBtn.setLcDeploymentId(lcNodeAttribute.getHid_());
					lcNodeBtn.setLcNodeAttributeId(lcNodeAttribute.getId());
					lcNodeBtn.setId(toUUID());
					lcNodeBtnDao.addLcNodeBtn(lcNodeBtn);
					List<LcJumpRules> lcJumpRules = lcNodeBtn.getLcJumpRules();
					if(!CollectionUtil.isEmpty(lcJumpRules)){
						for(LcJumpRules lcJumpRule : lcJumpRules){
							lcJumpRule.setUpdateId(getCurrentAccountId());
							lcJumpRule.setUpdateTime(getDate());
							lcJumpRule.setId(toUUID());
							lcJumpRule.setNodeBtnId(lcNodeBtn.getId());//设置按钮id
							lcJumpRule.setNodeId(lcNodeAttribute.getNodeId());
							lcJumpRule.setLcNodeAttributeId(lcNodeAttribute.getId());
							lcJumpRulesDao.addLcJumpRules(lcJumpRule);
						}
					}
				}
			}

			//3.处理跳转规则
			if(!CollectionUtil.isEmpty(lcNodeAttribute.getLcJumpRules())){
//				Map<String,Object> condition = new HashMap<>();
//				condition.put("lcNodeAttributeId",lcNodeAttribute.getId());
//				condition.put("unNeedDelBtn",false);
//				lcJumpRulesDao.delLcJumpRulesByAttributeId(condition);//只删除节点（不包括按钮关联的节点）
				List<LcJumpRules> lcJumpRules = lcNodeAttribute.getLcJumpRules();
				for(LcJumpRules lcJumpRule : lcJumpRules){
					lcJumpRule.setUpdateId(getCurrentAccountId());
					lcJumpRule.setUpdateTime(getDate());
					lcJumpRule.setId(toUUID());
					lcJumpRule.setNodeId(lcNodeAttribute.getNodeId());
					lcJumpRule.setLcNodeAttributeId(lcNodeAttribute.getId());
					lcJumpRulesDao.addLcJumpRules(lcJumpRule);
				}
			}

			//4.处理审批人
			if(!CollectionUtil.isEmpty(lcNodeAttribute.getLcNodeCandidate())){
//				lcNodeCandidateDao.delLcNodeCandidateByAttributeId(lcNodeAttribute.getId());
				List<LcNodeCandidate> lcNodeCandidates = lcNodeAttribute.getLcNodeCandidate();
				for(LcNodeCandidate lcNodeCandidate : lcNodeCandidates){
					lcNodeCandidate.setLcDeploymentId(lcNodeAttribute.getHid_());
					lcNodeCandidate.setNodeId(lcNodeAttribute.getNodeId());
					lcNodeCandidate.setLcProcessId(lcNodeAttribute.getLcProcessId());
					lcNodeCandidate.setLcNodeAttributeId(lcNodeAttribute.getId());
					lcNodeCandidate.setUpdateId(getCurrentAccountId());
					lcNodeCandidate.setUpdateTime(getDate());
					lcNodeCandidate.setId(toUUID());
					lcNodeCandidateDao.addLcNodeCandidate(lcNodeCandidate);
				}
			}

			//5.字段权限
			if(!CollectionUtil.isEmpty(lcNodeAttribute.getNodeFormField())){
				lcNodeFormFieldDao.delLcNodeFormFieldAttributeId(lcNodeAttribute.getId());
				List<LcNodeFormField> lcNodeFormFields = lcNodeAttribute.getNodeFormField();
				for(LcNodeFormField lcNodeFormField : lcNodeFormFields){
					lcNodeFormField.setUpdateId(getCurrentAccountId());
					lcNodeFormField.setUpdateTime(getDate());
					lcNodeFormField.setId(toUUID());
					lcNodeFormField.setNodeId(lcNodeAttribute.getNodeId());
					lcNodeFormField.setLcNodeAttributeId(lcNodeAttribute.getId());
					lcNodeFormFieldDao.addLcNodeFormField(lcNodeFormField);
				}
			}
		} catch (Exception e) {
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}

	/**
	 * 根据节点id+部署记录查找唯一
	 * @param nodeAttributeParam
	 * @return
	 */
	public LcNodeAttribute getLcNodeAttribute(NodeAttributeParam nodeAttributeParam){
		LcNodeAttribute lcNodeAttribute = lcNodeAttributeDao.getLcNodeAttribute(nodeAttributeParam);
		if(null != lcNodeAttribute){
			if(!StringUtil.isEmpty(lcNodeAttribute.getMountsId())){//查询bpm文件
				LcProcess lcProcess = lcProcessDao.getLcProcessById(lcNodeAttribute.getMountsId());
				if(null != lcProcess){
					lcNodeAttribute.setBpm(lcProcess.getBpmn());
				}
			}
			if(!StringUtil.isEmpty(lcNodeAttribute.getHid_())){//查询bpm文件
				LcDeploymentHis lcDeploymentHis = lcDeploymentHisDao.getLcDeploymentHisById(lcNodeAttribute.getHid_());
				if(null != lcDeploymentHis){
					lcNodeAttribute.setBpm(lcDeploymentHis.getBpmn());
				}
			}
			String lcNodeAttributeId = lcNodeAttribute.getId();
			Map<String,Object> condition = new HashMap<>();
			condition.put("lcNodeAttributeId",lcNodeAttributeId);
			List<LcJumpRules> lcJumpRules = lcJumpRulesDao.getLcJumpRulesListByCondition(condition);
			List<LcJumpRules> btnRules = new ArrayList<>();
			if(!CollectionUtil.isEmpty(lcJumpRules)){
				List<LcJumpRules> jumpRulesList = new ArrayList<>();
				//过滤掉按钮下的自由规则
				for(LcJumpRules rules : lcJumpRules){
					if(StringUtil.isEmpty(rules.getNodeBtnId())){
						jumpRulesList.add(rules);
					}else{
						btnRules.add(rules);
					}
				}
				if(!CollectionUtil.isEmpty(jumpRulesList)){
					lcNodeAttribute.setLcJumpRules(jumpRulesList);
				}
			}
			List<LcNodeBtn> lcNodeBtns = lcNodeBtnDao.getLcNodeBtnListByCondition(condition);
			if(!CollectionUtil.isEmpty(lcNodeBtns)){
				for(LcNodeBtn lcNodeBtn : lcNodeBtns){
					if(StringUtil.isEmpty(lcNodeBtn.getBtnLabel())){
						lcNodeBtn.setBtnLabel(lcNodeBtn.getLabel_());//如果自定义按钮扩展label不存在则调用按钮中label
					}
					if(StringUtil.isEmpty(lcNodeBtn.getBtnAction())){
						lcNodeBtn.setBtnAction(lcNodeBtn.getAction_());//如果自定义扩展action为空 则调用按钮中action
					}
					if(!StringUtil.isEmpty(lcNodeBtn.getId())){
						List<LcJumpRules> lcBtnRules = new ArrayList<>();
						if(!CollectionUtil.isEmpty(btnRules)){
							for(LcJumpRules rules: btnRules){
								if(rules.getNodeBtnId().equals(lcNodeBtn.getId())){
									lcBtnRules.add(rules);
								}
							}
						}
						if(!CollectionUtil.isEmpty(lcBtnRules)){
							lcNodeBtn.setLcJumpRules(lcBtnRules);//设置按钮对应的节点跳转规则
						}
						lcNodeBtn.setLcBtn(lcBtnDao.getLcBtnById(lcNodeBtn.getBtnId()));
					}
				}
				lcNodeAttribute.setLcNodeBtns(lcNodeBtns);
			}
			List<LcNodeCandidate> lcNodeCandidates = lcNodeCandidateDao.getLcNodeCandidateListByCondition(condition);
			if(!CollectionUtil.isEmpty(lcNodeCandidates)){
				if(lcNodeCandidates.size() > 1){
					throw new ExceptionUtil("查出多个审批记录，错误！");
				}
				lcNodeAttribute.setLcNodeCandidate(lcNodeCandidates);
			}

			List<LcNodeFormField> lcNodeFormFields = lcNodeFormFieldDao.getLcNodeFormFieldListByCondition(condition);
			if(!CollectionUtil.isEmpty(lcNodeFormFields)){
				lcNodeAttribute.setNodeFormField(lcNodeFormFields);
			}

			//处理通知模板
			if(!StringUtil.isEmpty(lcNodeAttribute.getNotifyTemplateIds())){
				condition = new HashMap<>();
				condition.put("notifyTemplateIds",lcNodeAttribute.getNotifyTemplateIds().split(","));
			}
			List<LcNotifyTemplate> lcNotifyTemplates =  lcNotifyTemplateDao.getLcNotifyTemplateListByCondition(condition);
			if(!CollectionUtil.isEmpty(lcNotifyTemplates)){
				lcNodeAttribute.setLcNotifyTemplates(lcNotifyTemplates);
			}
		}
		return lcNodeAttribute;
	}

	/**
	 * 根据编号删除
	 * @param id
	 * @return
	 */
	public int delLcNodeAttributeById(String id){
		int i = 0;
		if(!StringUtil.isEmpty(id)){
			Map<String,Object> condition = new HashMap<>();
			condition.put("lcNodeAttributeId",id);
			lcJumpRulesDao.delLcJumpRulesByAttributeId(condition);//1.删除跳转规则
			lcNodeBtnDao.delLcNodeBtnByAttributeId(id);//2.删除节点按钮
			lcNodeCandidateDao.delLcNodeCandidateByAttributeId(id);//3.删除办理人
			lcNodeFormFieldDao.delLcNodeFormFieldAttributeId(id);//4.删除节点字段
			i = lcNodeAttributeDao.delLcNodeAttributeById(id);//5.删除主节点
		}
		return i;
	}

	/**
	 * 根据挂载编号（流程主模板id即最新版本）删除节点配置
	 * @param mountsId
	 * @return
	 */
	public int delLcNodeAttributeByMountsId(String mountsId){
		int i = 0;
		Map<String,Object> condition = new HashMap<>();
		condition.put("mountsId",mountsId);
		List<LcNodeAttribute> lcNodeAttributeList = lcNodeAttributeDao.getLcNodeAttributeListByCondition(condition);
		if(!CollectionUtil.isEmpty(lcNodeAttributeList)){
			for(LcNodeAttribute lcNodeAttribute: lcNodeAttributeList){
				i = delLcNodeAttributeById(lcNodeAttribute.getId());
			}
		}
		return i;
	}
}